define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'goods_one_type/index' + location.search,
                    add_url: 'goods_one_type/add',
                    edit_url: 'goods_one_type/edit',
                    del_url: 'goods_one_type/del',
                    multi_url: 'goods_one_type/multi',
                    import_url: 'goods_one_type/import',
                    table: 'goods_one_type',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {field: 'name', title: __('Name')},
                        {field: 'weigh', title: __('Weigh')},
                        {field: 'is_yc_switch', title: __('是否隐藏'), operate: false, searchList: {"0":__('显示'),"1":__('隐藏')}, table: table, formatter: Table.api.formatter.toggle},
                        
                        {field: 'id', title: __('二级分类设置'), formatter: Controller.api.formatter.id,operate:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                search:false,
                showColumns: false,
                showToggle: false,
                showExport: false,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {
                id: function (value, row, index) {
                    //这里手动构造URL
                    var ids = row['id'];
                    url = "goods_two_type?ids=" + ids;
                    //方式一,直接返回class带有addtabsit的链接,这可以方便自定义显示内容
                    return '<a href="' + url + '" class="label label-success addtabsit" title="' + __("二级分类", value) + '">' + '二级分类' + '</a>';
                }
            }
        }
    };
    return Controller;
});